from django.http import JsonResponse
from django.shortcuts import redirect, render

class MyMiddleware():
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.
        whitelist = [
            '/',
            '/admin/',
            '/account/get_user_info/',
            '/register/',
            '/login/',
            '/getprice_customer/',
            '/getprice_merchant/',
            '/getpricebyid/',
            '/saveprice/',
            '/addprice/',
            '/deleteprice/',
            '/getallorders_merchant/',
            '/getmerlist/',
            '/getmerchant/',
            '/getorderby_id/',
            '/placeorder/',
            '/getordering/',
            '/getallordersby_cus/',
            '/getselfinfo/',
            '/saveinfo/',
            '/getunderway/',
            '/updateorder/',
            '/searchorder/',
            '/favicon.ico',
        ]
        url = request.path
        if url not in whitelist:
            print(url)
            #return redirect('/')

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response